<template>
  <div class="app-container">
    <el-button type="primary" @click="add">添加产品</el-button>

    <el-table :data="productList" style="width: 100%">
      <el-table-column prop="name" label="产品名称"> </el-table-column>
      <el-table-column prop="productKey" label="ProductKey"> </el-table-column>
      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-edit"
            @click="xq(scope.row)"
            >详情</el-button
          >
          <el-button @click="del(scope.row)" type="danger" size="mini" icon="el-icon-delete">删除</el-button>     
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageDto.now"
      :page-sizes="[5, 10, 50, 100]"
      :page-size="pageDto.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <el-dialog title="产品详情" :visible.sync="dialogTableVisible">
      <el-form :model="product">
        <el-form-item label="产品ID"  >
        :{{ product.id}}
        </el-form-item>
        <el-form-item label="产品名称" >
        : {{ product.name }}
        </el-form-item>
        <el-form-item label="ProductKey	" >
        : {{ product.productKey }}
        </el-form-item>
        <el-form-item label="用户名" >
        : {{ product.username }}
        </el-form-item>
        <el-form-item label="密码"  >
        : {{ product.password }}
        </el-form-item>
        <el-form-item label="创建时间"  >
        : {{ product.createTime }}
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { page , del} from "@/api/product";
export default {
  data() {
    return {
      dialogTableVisible:false,
      pageDto: {
        now: 1,
        size: 5,
      },
      total: "",
      productList: [],
      product:[{
        areaCode:"",
        createTime: "",
        deleted:"",
        id:"",
        name:"",
        password:"",
        productKey:"",
        tenantId:"",
        updateTime:"",
        username:"",
      }]
    };
  },
  methods: {
    search() {
      page(this.pageDto).then((res) => {
        this.productList = res.data.list;
        console.log(this.productList);
        this.total = res.data.total;
      });
    },
    handleSizeChange(size) {
      this.pageDto.size = size;
      this.search();
    },
    handleCurrentChange(now) {
      this.pageDto.now = now;
      this.search();
    },
    add() {
      this.$router.push({ path: "/product/add" });
    },
    //查看详情
    xq(data){
        this.dialogTableVisible = true;
        this.product = data
        console.log(this.product);
    },
    //删除
    del(data){
        del(data).then(res=>{
          this.$message({
            message:res.ok?"删除成功":"删除失败",
            type:res.ok?"success":"error"
          })
        })
        this.search()
    }
  },
  created() {
    this.search();
  },
};
</script>
<style>
</style>